home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / examples / inherit1.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  3KB  |  122 lines

  1.  
  2. static char rcsid[] =
  3.     "$Id: inherit1.c,v 1.3 1997/07/09 13:24:47 pvmsrc Exp $";
  4.  
  5. /*
  6.  *         PVM version 3.4:  Parallel Virtual Machine System
  7.  *               University of Tennessee, Knoxville TN.
  8.  *           Oak Ridge National Laboratory, Oak Ridge TN.
  9.  *                   Emory University, Atlanta GA.
  10.  *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
  11.  *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
  12.  *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
  13.  *                   (C) 1997 All Rights Reserved
  14.  *
  15.  *                              NOTICE
  16.  *
  17.  * Permission to use, copy, modify, and distribute this software and
  18.  * its documentation for any purpose and without fee is hereby granted
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both the copyright notice and this permission notice appear in
  21.  * supporting documentation.
  22.  *
  23.  * Neither the Institutions (Emory University, Oak Ridge National
  24.  * Laboratory, and University of Tennessee) nor the Authors make any
  25.  * representations about the suitability of this software for any
  26.  * purpose.  This software is provided ``as is'' without express or
  27.  * implied warranty.
  28.  *
  29.  * PVM version 3 was funded in part by the U.S. Department of Energy,
  30.  * the National Science Foundation and the State of Tennessee.
  31.  */
  32.  
  33. /*
  34.  *    Filename:     inherit1.c
  35.  *
  36.  *  support program for inherita.c - read docs in that file
  37.  */
  38.  
  39. #ifndef WIN32
  40. #include <unistd.h>        /* for gethostname */
  41. #else
  42. #include "pvmwin.h"
  43. #endif
  44. #include "pvm3.h"
  45.  
  46. main()
  47. {
  48.     char *me = "inherit1";
  49.     int cc, tid, ptid;
  50.     char buf[100], buf2[100];
  51.     char machine[25];
  52.     int mycontext;
  53.  
  54.     ptid = pvm_parent();
  55.  
  56.     mycontext = pvm_getcontext();
  57.     gethostname( machine, 25 );
  58.  
  59.     sprintf( buf, "%s t%x on machine <%s> with context %d.",
  60.             me, pvm_mytid(), machine, mycontext );
  61.  
  62.     /* Send message to parent */
  63.     pvm_initsend( PvmDataDefault );
  64.     pvm_pkstr( buf );
  65.     pvm_send( ptid, 1 );
  66.  
  67.     /*
  68.      *  Spawn a child process to confirm that it will inherit the
  69.      *   parent context.
  70.      */
  71.     cc = pvm_spawn( "inherit2", (char **) 0, PvmTaskDefault, "", 1,
  72.             &tid );
  73.     if ( cc != 1 ){
  74.         printf( "%s: can't start inherit2\n", me );
  75.         pvm_exit();
  76.         exit( 0 );
  77.     }
  78.  
  79.     sprintf( buf,
  80.             "%s: I just spawned inherit2 as tid t%x with context %d.\n",
  81.             me, tid, pvm_getcontext() );
  82.  
  83.     /* Send message to parent */
  84.     pvm_initsend( PvmDataDefault );
  85.     pvm_pkstr( buf );
  86.     pvm_send( ptid, 1 );
  87.  
  88.     /*
  89.      *  wait to receive message from child
  90.      */
  91.     cc = pvm_recv( -1, -1 );
  92.     pvm_bufinfo( cc, (int *) 0, (int *) 0, &tid );
  93.     pvm_upkstr( buf2 );
  94.     sprintf( buf, "%s: t%x %s\n", me, tid, buf2 );
  95.  
  96.     /* Send message to parent */
  97.     pvm_initsend( PvmDataDefault );
  98.     pvm_pkstr( buf );
  99.     pvm_send( ptid, 1 );
  100.  
  101.     sprintf( buf, "%s t%x on machine <%s> with context %d.",
  102.             me, pvm_mytid(), machine, mycontext );
  103.  
  104.     /* Send message to parent */
  105.     pvm_initsend( PvmDataDefault );
  106.     pvm_pkstr( buf );
  107.     pvm_send( ptid, 1 );
  108.  
  109.     sprintf( buf,
  110.             "END - sent from %s t%x on machine <%s> with context %d.",
  111.             me, pvm_mytid(), machine, mycontext );
  112.  
  113.     /* Send message to parent */
  114.     pvm_initsend( PvmDataDefault );
  115.     pvm_pkstr( buf );
  116.     pvm_send( ptid, 1 );
  117.  
  118.     pvm_exit();
  119.     exit( 0 );
  120. }
  121.  
  122.